"""
@File         : models.py
@Time         : 2024/05/08 18:08:50
@Author       : Qrj
@Email        : 923207736@qq.com
@Description  : 站内信消息记录相关数据模型
"""

from datetime import datetime

from sqlalchemy import JSON, BigInteger, Boolean, Column, DateTime, Index, String

from src.business.admin.system.station_message.enums import (
    StationMessageTypeEnum,
)
from src.enums.datetime import CONSTANT_NOT_DATETIME
from src.models.models import OrmBase


class StationMessageRecord(OrmBase):
    """站内信消息记录数据模型"""

    __tablename__ = "system_station_message_record"
    __table_args__ = (
        Index(None, "receiver_id", "tenant_id"),
        Index(None, "type", "tenant_id"),
    )

    id = Column(BigInteger(), primary_key=True, autoincrement=True, comment="主键")
    content = Column(String(2048), nullable=False, comment="消息内容")
    type = Column(
        String(10),
        nullable=False,
        default=StationMessageTypeEnum.info.value,
        comment="消息类型",
    )
    template_params = Column(JSON(), nullable=False, default={}, comment="模板参数")
    # 发送时间
    sending_datetime = Column(
        DateTime(), nullable=False, default=datetime.now, index=True, comment="发送时间"
    )
    # 创建者用户名(发送者)
    sender_username = Column(
        String(20), default="", nullable=False, comment="发送者用户名"
    )
    receiver_id = Column(BigInteger(), nullable=False, comment="接收者ID")
    receiver_username = Column(String(20), nullable=False, comment="接收者用户名")
    read_status = Column(Boolean(), nullable=False, default=False, comment="是否已读")
    read_datetime = Column(
        DateTime(),
        nullable=False,
        default=CONSTANT_NOT_DATETIME,
        index=True,
        comment="查看时间",
    )
    # 租户ID(级联删除)
    tenant_id = Column(BigInteger(), nullable=False, index=True, comment="租户ID")
    template_id = Column(BigInteger(), nullable=False, index=True, comment="模板ID")
    template_name = Column(String(50), nullable=False, comment="模板名称")
